package net.core.common;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringContext {

	private static ApplicationContext ctx = null;

	static {
		try {
			ctx = new ClassPathXmlApplicationContext(
					new String[] { "resources/applicationContext*.xml" });
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static Object getBean(String beanId) {
		try {
			Object object = null;
			if (ctx == null) {
				System.out.println("@@@@SpringContext  没有初始化ApplicationContext!!");
				throw new Exception("没有初始化ApplicationContext!!");
			} else {
				object = ctx.getBean(beanId);
			}
			return object;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
